package demoMod.gdxform.core;

import java.util.ArrayList;
import java.util.List;

public class ActionManager {
    private final List<AbstractAction> sequenceActionQueue = new ArrayList<>();

    private final List<AbstractAction> parallelActionQueue = new ArrayList<>();

    public void update() {
        if (!sequenceActionQueue.isEmpty()) {
            AbstractAction action = sequenceActionQueue.get(0);
            if (action.update()) {
                sequenceActionQueue.remove(action);
            }
        }
        List<AbstractAction> toRemove = new ArrayList<>();
        for (AbstractAction action : parallelActionQueue) {
            if (action.update()) {
                toRemove.add(action);
            }
        }
        parallelActionQueue.removeAll(toRemove);
    }

    public void clearSequence() {
        sequenceActionQueue.clear();
    }

    public void addToSequenceBot(AbstractAction action) {
        sequenceActionQueue.add(action);
    }

    public void addToSequenceTop(AbstractAction action) {
        sequenceActionQueue.add(0, action);
    }

    public void addToParallelBot(AbstractAction action) {
        parallelActionQueue.add(action);
    }

    public void addToParallelTop(AbstractAction action) {
        parallelActionQueue.add(0, action);
    }
}
